package com.fire.eyes.service.impl;

import com.fire.eyes.model.TMitActivity;
import com.fire.eyes.dao.TMitActivityMapper;
import com.fire.eyes.service.ITMitActivityService;
import com.fire.eyes.util.ImageUtil;
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;

import java.sql.SQLException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * <p>
 * 活动表 服务实现类
 * </p>
 *
 * @author raoyuxing123
 * @since 2018-05-10
 */
@Service
public class TMitActivityServiceImpl extends ServiceImpl<TMitActivityMapper, TMitActivity> implements ITMitActivityService {

	private static final Logger blogin = LoggerFactory.getLogger("blogin");
	 
	@Autowired
	private TMitActivityMapper activityMapper;
	@Autowired
	private ImageUtil imageUtil;
	
	@SuppressWarnings("unchecked")
	@Override
	public Map queryActivityList(Map map) throws SQLException {
		
		blogin.debug("TMitActivityServiceImpl.queryActivityList.debug 参数："+map);
		
		EntityWrapper<TMitActivity> wrapper = new EntityWrapper<>();
		wrapper.eq("channelid", map.get("chanelid")).eq("status", 1);
		List<TMitActivity> list = activityMapper.selectList(wrapper);
		
		Map resultMap = new HashMap<>(1);
		List activityList = new ArrayList<>();
		for (TMitActivity tMitActivity : list) {
			Map result = new HashMap<>(10);
			result.put("activityid", tMitActivity.getActivityid());
			String picurl = imageUtil.imageUrlConvert(tMitActivity.getPicurl());
			result.put("picurl", picurl);
			result.put("name", tMitActivity.getName());
			result.put("entryurl", tMitActivity.getEntryurl());
			result.put("exiturl", tMitActivity.getExiturl());
			result.put("promotion", tMitActivity.getPromotion());
			result.put("createtime", tMitActivity.getCreatetime());
			result.put("starttime ", tMitActivity.getStarttime());
			result.put("expiretime", tMitActivity.getExpiretime());
			result.put("status", tMitActivity.getStatus());
			activityList.add(result);
		}
		
		resultMap.put("activitylist", activityList);
		
		return resultMap;
	}

}
